package org.example.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.pojo.Business;
import org.example.pojo.Category;
import org.example.pojo.Query;
import org.example.service.CategoryService;
import org.example.mapper.CategoryMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 13326
* @description 针对表【hards_category】的数据库操作Service实现
* @createDate 2025-01-02 20:12:28
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{
    @Resource
    private CategoryMapper categoryMapper;
    @Override
    public Result getlist(Query query){

        LambdaQueryWrapper<Category> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(!StringUtils.isEmpty(query.getKeyword()), Category::getCname,query.getKeyword())
                .eq(Category::getCname,query.getKeyword());
        IPage<Category> page=new Page<>(query.getPageNum(),query.getPageSize());
        categoryMapper.selectPageMap(page,query);
        HashMap<String,Object> map=new HashMap<>();
        map.put("total",page.getTotal());
        map.put("rows",page.getRecords());
        map.put("pages",page.getPages());
        map.put("size",page.getSize());
        return Result.ok(map);

    }
    @Override
    public Result add(Category category){
        int rows=categoryMapper.insert(category);
        return Result.ok("新增成功");
    }
    @Override
    public Result updatecate(Category category){
        int rows=categoryMapper.updateById(category);
        return Result.ok("修改成功");
    }
    @Override
    public Result deletebyid(Integer id){
        int rows=categoryMapper.deleteById(id);
        return Result.ok("删除成功");
    }
    @Override
    public Result selectById(Integer id){
        List<Category> list=categoryMapper.selectbyId(id);
        return Result.ok(list);
    }


}




